package dawn.ioc;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import dawn.service.Service;

public class DefaultContext implements IContext {

	private static final Logger log = LoggerFactory.getLogger(DefaultContext.class);

	private Map<Class<Service>, Service> map = new HashMap<Class<Service>, Service>();

	@SuppressWarnings("unchecked")
	@Override
	public void add(Service obj) {
		map.put((Class<Service>) obj.getClass(), obj);
		log.info("add:", obj.getClass().getName());
	}

	@Override
	public List<Service> getServiceList() {
		return new ArrayList<Service>(map.values());
	}

	@SuppressWarnings("unchecked")
	@Override
	public <T> T get(Class<? extends Service> clazz) {
		return (T) map.get(clazz);
	}
}
